# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/dev-libs/qsa/qsa-1.1.1.ebuild,v 1.4 2005/07/25 15:40:59 caleb Exp $

inherit eutils qt4

S="${WORKDIR}/${PN}-x11-opensource-${PV}"

DESCRIPTION="Qt Script for Applications, a ECMAScript based scripting toolkit for making customizable Qt/C++ applications."
SRC_URI="ftp://ftp.trolltech.com/qsa/source/${PN}-x11-opensource-${PV}.tar.gz"
HOMEPAGE="http://www.trolltech.com/"
LICENSE="GPL-2"

SLOT="4"
KEYWORDS="~x86 ~amd64"
IUSE="doc examples ide debug"
DEPEND=">=x11-libs/qt-4.2.0"

src_compile() {
	local myconf="-prefix ${D}$(qmake -query QT_INSTALL_LIBS)"

	epatch ${FILESDIR}/${P}-QT_INSTALL.patch
	epatch ${FILESDIR}/${P}-QT_INSTALL-1.patch

	if ! use ide; then
		myconf="${myconf} -no-ide -no-editor"
		epatch ${FILESDIR}/${P}-without-examples-using-ide.diff
	fi

	if use examples; then
		epatch ${FILESDIR}/${P}-with-examples.diff
	else
		epatch ${FILESDIR}/${P}-without-examples.diff
	fi

	unset QTDIR
	./configure ${myconf} -release || die
	emake sub-src || die

	if use debug; then 
	    ./configure ${myconf} -debug || die
	    emake sub-src || die
	fi
}

src_install() {
	into $(qmake -query QT_INSTALL_PREFIX)

	#includes
	insinto $(qmake -query QT_INSTALL_HEADERS)
	doins src/qsa/*.h

	#QSA mkspec feature
	insinto $(qmake -query QT_INSTALL_DATA)/mkspecs/features
	doins src/qsa/qsa.prf

	#libs
	insinto $(qmake -query QT_INSTALL_LIBS)
	doins lib/lib*

	#QSA plugin (SEditor) for Qt designer 
	#insinto $(qmake -query QT_INSTALL_PLUGINS)/designer
	#doins plugins/designer/libqseditorplugin.so

	#documentation
	if use doc; then
		dohtml -A dcf -r doc/html/*
	fi

	#examples
	if use examples; then
		insinto /usr/share/doc/${PF}
		doins -r examples
	fi

	dodoc README changes-1.2.1
}

pkg_postinst(){
	if use doc && [ "${ROOT}" = "/" ]; then
		#include QSA Documentation content file into assistant
		assistant -addContentFile /usr/share/doc/${PF}/html/qsa.dcf
	fi
}

pkg_prerm(){
	if use doc && [ "${ROOT}" = "/" ]; then
		#remove QSA Documentation content file into assistant
		assistant -removeContentFile /usr/share/doc/${PF}/html/qsa.dcf
	fi
}
